package com.android.smsmb.mui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.Toast;
import com.android.smsmb.mui.banks.AvalBank;
import com.android.smsmb.mui.banks.PrivatBank;
import com.android.smsmb.mui.banks.UniCredit;
import com.android.smsmb.mui.builder.AbstractOperations;
import com.android.smsmb.mui.builder.BankDataModel;
import com.android.smsmb.mui.builder.OperationsHandler;

/**
 * Created by andrew on 7/11/14.
 */
public class CardMenuListFragment extends Fragment {
    private static  final String LOG_TAG = OperationsHandler.class.getName();

    AbstractOperations bank = null;
    String operation = "getBalance";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        final View rootView = inflater.inflate(R.layout.banks_grid, container, false);

        Toast.makeText(getActivity().getApplicationContext(), operation, Toast.LENGTH_SHORT).show();
        //PRIVAT
        ImageButton btnBal = (ImageButton)rootView.findViewById(R.id.btnPrivat);
        btnBal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //берем опцию "ПриватБанк" из бд или sharedpreferences
                userChoice("ПриватБанк");
                handler();
                Toast.makeText(getActivity().getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
            }
        });
        //AVAL
        ImageButton btnReplMobTel = (ImageButton)rootView.findViewById(R.id.btnAval);
        btnReplMobTel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userChoice("Аваль");
                handler();
                Toast.makeText(getActivity().getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
            }
        });

        // Unicredit
        ImageButton btnMoneyTransfer = (ImageButton)rootView.findViewById(R.id.btnUnicredit);
        btnMoneyTransfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userChoice("UniCredit");
                handler();
                Toast.makeText(getActivity().getApplicationContext(), "3", Toast.LENGTH_SHORT).show();
            }
        });
        return rootView;
    }

    public void userChoice(String cardID){
        switch (cardID) {
        case "ПриватБанк":
            bank = new PrivatBank();
            Toast.makeText(getActivity().getApplicationContext(), bank.toString(), Toast.LENGTH_SHORT).show();
            break;
        case "UniCredit":
            bank = new UniCredit();
            break;
        case "Аваль":
            bank = new AvalBank();
        }
    }
    public void handler() {
        String request = "";
        BankDataModel bdm = new BankDataModel("1111222233334444", 1, "9847342354226711", "555", null, -1, -1, "qw");
        switch (operation) {
            case "blockCard":
                request = bank.blockCard(bdm);
                Log.i("AAAAAAAAAAAAAAAAAAAAAAAAAa" + LOG_TAG, request);

                break;
            case "unblockCard":
                request = bank.unblockCard(bdm);
                Log.i("AAAAAAAAAAAAAAAAAAAAAAAAAa" + LOG_TAG, request);

                break;
            case "moneyTransfer":
                request = bank.moneyTransfer(bdm);
                Log.i("AAAAAAAAAAAAAAAAAAAAAAAAAa" + LOG_TAG, request);

                break;
            case "getBalance":
                request = bank.getBalance(bdm);
                Log.i("AAAAAAAAAAAAAAAAAAAAAAAAAa" + LOG_TAG, request);

                break;
            case "mobileTransfer":
                request = bank.mobileTransfer(bdm);
                Log.i("AAAAAAAAAAAAAAAAAAAAAAAAAa" + LOG_TAG, request);
                break;
            default:
                Log.i("AAAAAAAAAAAAAAAAAAAAAAAAAa" + LOG_TAG, "Pizdec");
        }

    }
}


